879E - Tournament - CodeForces Solution


data structures *2700

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>

using namespace std;
set<pair<int,int> >::iterator it;
int sef[500005];
int sz[500005];
int mat2[15][500005];
int mat3[15][500005];
int mat[15][500005];
int n,k;
struct grup
{
    int sz,mat3[15],mat2[15];
    bool operator < (const grup&rhs) const
    {
        for(int j=1; j<=k; j++)if(mat2[j]>rhs.mat3[j])return 0;
        return 1;
    }
};
set<grup>st;
void merge(grup x,grup y)
{
    int i;
    x.sz+=y.sz;
    for(i=1; i<=k; i++)
    {
        x.mat3[i]=min(x.mat3[i],y.mat3[i]);
        x.mat2[i]=max(x.mat2[i],y.mat2[i]);
    }
}
int main()
{
    long long n,i,j,l,z,m,a,b,t=1,suma=0,h,poz1,poz2,x,y,c,d,c1,c2,nra,nrc,sol,x2,y2,val,op,q,tip,gc,prod,u,dr,diffst,diffdr,ramase,nr,cate,curr,rez,rad,rest,ultimu,primu,leng,e,f,semn   ;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    t=1;
    string s;
    string s1;
    char ch;
    cin>>n>>k;
    for(i=1; i<=n; i++)
    {
        sef[i]=i;
        sz[i]=1;
    }
    for(i=1; i<=n; i++)
    {
        grup curr;
        for(j=1; j<=k; j++)
        {
            cin>>mat[j][i];
            curr.mat2[j]=mat[j][i];
            curr.mat3[j]=mat[j][i];
            curr.sz=1;
        }
        set <grup> :: iterator l, r;
        l=st.lower_bound(curr);
        r=st.upper_bound(curr);
        while(l!=r)
        {
            curr.sz+=l->sz;
            for(j=1; j<=k; j++)
            {
                curr.mat3[j]=min(curr.mat3[j],l->mat3[j]);
                curr.mat2[j]=max(curr.mat2[j],l->mat2[j]);
            }
            st.erase(l++);
        }
        st.insert(curr);
        cout<<st.rbegin()->sz<<endl;
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

1618A - Polycarp and Sums of Subsequences
1618B - Missing Bigram
938. Range Sum of BST
147. Insertion Sort List
310. Minimum Height Trees
2110. Number of Smooth Descent Periods of a Stock
2109. Adding Spaces to a String
2108. Find First Palindromic String in the Array
394. Decode String
902. Numbers At Most N Given Digit Set
221. Maximal Square
1200. Minimum Absolute Difference
1619B - Squares and Cubes
1619A - Square String
1629B - GCD Arrays
1629A - Download More RAM
1629C - Meximum Array
1629D - Peculiar Movie Preferences
1629E - Grid Xor
1629F1 - Game on Sum (Easy Version)
2148. Count Elements With Strictly Smaller and Greater Elements
2149. Rearrange Array Elements by Sign
2150. Find All Lonely Numbers in the Array
2151. Maximum Good People Based on Statements
2144. Minimum Cost of Buying Candies With Discount
Non empty subsets
1630A - And Matching
1630B - Range and Partition
1630C - Paint the Middle
1630D - Flipping Range